<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="date">
        <p id="nowDate">

        </p>
        <p id="day">

        </p>
    </div>
<script type="text/javascript">
    // 1. 获取标签
    var nowDate = document.getElementById('nowDate');
    var day = document.getElementById('day');

    // 用定时器 更新时间的变化
    setInterval(nowNumTime, 1000);
    // nowDate.innerHTML = '2019年4月30日'

    function nowNumTime(){
        var now = new Date();
        var hour = now.getHours(); // 0~23
        var minute = now.getMinutes();
        var second = now.getSeconds();
        var year = now.getFullYear();
        var month = now.getMonth();
        var d = now.getDate();
        var week = now.getDay();
        console.log(week);
        var weeks = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
        var temp = '' + (hour > 12 ? hour - 12 : hour);
        if(hour === 0){
            temp = '12';
        }
        temp = temp + (minute < 10 ? ':0':":") + minute;
        temp = temp +(second < 10 ? ':0':":")+ second;
        temp = temp + (hour >= 12 ? 'P.M.':"A.M.");
        temp = `${year}年${month}月${d}日 ${temp} ${weeks[week]}`;

        nowDate.innerHTML = temp;
        // return temp;
    }
    var nownum = nowNumTime();
    console.log(nownum)

</script>

</body>
</html>